package com.zpark.pay_face_to_face.controller;

import cn.hutool.extra.qrcode.QrCodeUtil;
import com.zpark.pay_face_to_face.service.IPToPPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: com.zpark.pay_face_to_face.controller
 * @ClassName: PayPToPController
 * @Description:
 * @author: RZS
 * @date: 2024/6/4  9:09
 */
@RestController
@RequestMapping("/p_to_p")
public class PayPToPController {

    @Autowired
    private IPToPPayService payService;

    // 测试二维码使用
    @RequestMapping("/test")
    public void test(HttpServletResponse response) throws IOException {

        QrCodeUtil.generate("http://www.jd.com",
                300, 300, "png", response.getOutputStream());
    }

    @RequestMapping("/createOrder")
    public void createOrder(HttpServletResponse response) throws Exception {
        // 调用业务层方法
        String form = payService.createOrder();

        // 设置响应编码
        response.setContentType("text/html;charset=utf-8");

        // 通过response响应页面
        PrintWriter writer = response.getWriter();
        writer.write(form);
        writer.flush();
    }

    @RequestMapping("/create")
    public void createOrder2(HttpServletResponse response) throws Exception {
        // 调用业务层方法
        String qrCode = payService.createOrder2();

        QrCodeUtil.generate(qrCode, 300, 300,
                "png", response.getOutputStream());
    }
}
